On Track Event
Emitted whenever the SDK detects a trackable event—typically QR‑based interactions or out‑of‑band invitations—that it can surface for analytics, deep‑linking, or custom routing logic.
-
Purpose: Expose low‑level scan or invite events so your application can record analytics, navigate to appropriate screens, or trigger business‑specific flows.
-
Functionality: The handler receives a
TrackEventMessage
object:export type TrackEventMessage = {
messageType: QRType; // e.g. 'presentation-request', 'credential-offer'
message: string; // raw URL or payload string
};
export enum QRType {
PresentationRequest = 'presentation-request',
CredentialOffer = 'credential-offer',
OutOfBandInvitation = 'out-of-band-invitation',
OutOfBandStartFlow = 'out-of-band-start-flow',
Totp = 'totp',
Unknown = 'unknown'
} -
Usage:
- Analytics – log the event type and payload to your tracking system (e.g. Amplitude, Mixpanel).
- Routing – deep‑link users to the correct credential/ proof flow based on
messageType
. - Validation – pre‑validate the scanned string before handing it off to the SDK’s flow initiators.
-
Example:
import { TrackEventMessage } from '@one37id/mobile-js-sdk';
import { analytics } from '../services/analytics';
import { navigationService } from '../services/navigation';
const handlers: EventHandlers = {
onTrack: async (model: TrackEventMessage) => {
console.log(`Track event received: ${JSON.stringify(model, null, 2)}`);
// 1) analytics
analytics.logEvent('track_event', {
type: model.messageType,
payload: model.message,
});
// 2) routing
switch (model.messageType) {
case 'presentation-request':
navigationService.navigate('ProofRequest', { uri: model.message });
break;
case 'credential-offer':
navigationService.navigate('CredentialOffer', { uri: model.message });
break;
// handle other types as needed
default:
console.warn('Unknown track type, ignoring');
}
},
};